package org.jeecg.modules.monitoring.j_monitoring.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.monitoring.j_monitoring.entity.ScreenData;
import org.jeecg.modules.monitoring.j_monitoring.service.IScreenDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
* @Description: 大屏数据(管理)
* @Author: xiaoyq
* @Date:   2022-12-11
* @Version: V1.0
*/
@Api(tags="大屏数据(管理)")
@RestController
@RequestMapping("/j_monitoring/screenData")
@Slf4j
public class ScreenDataController extends JeecgController<ScreenData, IScreenDataService> {
   @Resource
   private IScreenDataService screenDataService;

   /**
    * 分页列表查询
    *
    * @param ScreenData
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   //@AutoLog(value = "大屏数据(管理)-分页列表查询")
   //@RequiresPermissions("网络资源:查询")
   @ApiOperation(value="大屏数据(管理)-分页列表查询", notes="大屏数据(管理)-分页列表查询")
   @GetMapping(value = "/list")
   public Result<?> queryPageList(ScreenData ScreenData,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       Result<Page<ScreenData>> result=new Result<>();
       Page<ScreenData> pagelist = new Page(pageNo, pageSize);
       QueryWrapper<ScreenData> queryWrapper = QueryGenerator.initQueryWrapper(ScreenData, req.getParameterMap());
       pagelist=screenDataService.page(pagelist,queryWrapper);
       result.setCode(200);
       result.setSuccess(true);
       result.setResult(pagelist);
       return result;
   }

   /**
    *   添加
    *
    * @param ScreenData
    * @return
    */
   @AutoLog(value = "大屏数据(管理)-添加")
   @ApiOperation(value="大屏数据(管理)-添加", notes="大屏数据(管理)-添加")
   //@RequiresPermissions("org.jeecg.modules.monitoring:大屏数据(管理):add")
   @PostMapping(value = "/add")
   public Result<String> add(@RequestBody ScreenData ScreenData) {
       screenDataService.save(ScreenData);
       return Result.OK("添加成功！");
   }

   /**
    *  编辑
    *
    * @param ScreenData
    * @return
    */
   @AutoLog(value = "大屏数据(管理)-编辑")
   @ApiOperation(value="大屏数据(管理)-编辑", notes="大屏数据(管理)-编辑")
   //@RequiresPermissions("org.jeecg.modules.monitoring:大屏数据(管理):edit")
   @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
   public Result<String> edit(@RequestBody ScreenData ScreenData) {
       screenDataService.saveOrUpdate(ScreenData);
       return Result.OK("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "大屏数据(管理)-通过id删除")
   @ApiOperation(value="大屏数据(管理)-通过id删除", notes="大屏数据(管理)-通过id删除")
   //@RequiresPermissions("org.jeecg.modules.monitoring:大屏数据(管理):delete")
   @DeleteMapping(value = "/delete")
   public Result<String> delete(@RequestParam(name="id",required=true) String id) {
       screenDataService.removeById(id);
       return Result.OK("删除成功!");
   }

   /**
    *  批量删除
    *
    * @param ids
    * @return
    */
   @AutoLog(value = "大屏数据(管理)-批量删除")
   @ApiOperation(value="大屏数据(管理)-批量删除", notes="大屏数据(管理)-批量删除")
   //@RequiresPermissions("org.jeecg.modules.monitoring:大屏数据(管理):deleteBatch")
   @DeleteMapping(value = "/deleteBatch")
   public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
       this.screenDataService.removeByIds(Arrays.asList(ids.split(",")));
       return Result.OK("批量删除成功!");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   //@AutoLog(value = "大屏数据(管理)-通过id查询")
   @ApiOperation(value="大屏数据(管理)-通过id查询", notes="大屏数据(管理)-通过id查询")
   @GetMapping(value = "/queryById")
   public Result<ScreenData> queryById(@RequestParam(name="id",required=true) String id) {
       ScreenData ScreenData = screenDataService.getById(id);
       if(ScreenData==null) {
           return Result.error("未找到对应数据");
       }
       return Result.OK(ScreenData);
   }

   /**
   * 导出excel
   *
   * @param request
   * @param ScreenData
   */
   //@RequiresPermissions("org.jeecg.modules.monitoring:大屏数据(管理):exportXls")
   @RequestMapping(value = "/exportXls", method = RequestMethod.GET)
   @ApiOperation(value="大屏数据(管理)-导出", notes="大屏数据(管理)-导出")
   public ModelAndView exportXls(HttpServletRequest request, ScreenData ScreenData) {
       return super.exportXls(request, ScreenData, ScreenData.class, "大屏数据(管理)");
   }

   /**
     * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
   //@RequiresPermissions("大屏数据(管理):importExcel")
   @ApiOperation(value="大屏数据(管理)-导入", notes="大屏数据(管理)-导入")
   @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
   public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
       return super.importExcel(request, response, ScreenData.class);
   }

}
